package com.heima.behavior.controller;

import com.heima.behavior.dto.BehaviorDto;
import com.heima.behavior.service.IApBehaviorEntryService;
import com.heima.common.dto.ResponseResult;
import com.heima.common.dto.User;
import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.common.util.UserThreadLocalUtil;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Mr_Su
 * @version v1.0
 * @date 2022/7/7 12:31
 * @desciption
 */
@RestController
@RequestMapping("/api/v1/behavior")
public class BehaviorController {

    @Autowired
    private IApBehaviorEntryService apBehaviorEntryService;

    @PostMapping("/load_article_behavior")
    @ApiOperation(value = "loadArticleBehavior",notes = "回显当前登录人对文章的行为")
    @ApiModelProperty(name = "dto",dataType = "BehaviorDto",required = true)
    public ResponseResult loadArticleBehavior(@RequestBody BehaviorDto dto){

        User user = UserThreadLocalUtil.get();
        if(user==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN);
        }
        dto.setUserId(user.getUserId());
        return apBehaviorEntryService.loadArticleBehavior(dto);
    }
}
